// pages/distribut/become_admin/become_admin.js
var app = getApp();
var request = app.request;
var common = require('../../../utils/common.js');
var auth = require('../../../utils/auth.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		istrue: false,
		binding: false,
		shop_id: ''
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(query) {
		let that = this
		 // const q = decodeURIComponent(query) 
		const q = decodeURIComponent(query.q) 
		console.log(q.split('='))
		that.setData({
			shop_id:q.split('=')[1]
		});

		// 	app.globalData.userInfo = {}


		// 	wx.clearStorageSync();
	},
	tz() {
		wx.reLaunch({
			url: '/pages/index/index/index'
		});
	},
	bindGetUserinfo: function(res) {
		let that = this;
		console.log(res)
		if (res.detail.userInfo != undefined) {
			try {
				wx.setStorageSync('wx_user_info', res.detail);
				app.globalData.wechatUser = res.detail.userInfo;
				wx.login({
					success: function(res1) {
						if (!res1.code) {
							wx.showModal({
								title: '获取用户登录态失败',
								content: res.errMsg,
								showCancel: false,
								complete: function() {
									that.goHome();
								}
							});
							return;
						}
						app.auth.checkLogin(res1.code, res.detail,
							function(loginData) {
								request.get(
									'/api/shop/applyShopManager', {
										data: {
											shop_id: res.currentTarget.dataset.id,
											code: res1.code,
											versionCode: '2.0.0',
											encryptedData: res
												.detail
												.encryptedData,
											iv: res.detail.iv,
											oauth: 'miniapp',
											nickname: res.detail
												.userInfo
												.nickname,
											head_pic: res.detail
												.userInfo
												.avatarUrl,
											sex: res.detail
												.userInfo
												.gender,
											terminal: 'miniapp',
											first_leader: ''
										},
										success: function(
											res2) {
											if (res2.data
												.status == 1
											) {
												wx.showToast({
													title: '申请成功'
												})
												that.setData({
													istrue:
														!
														that
														.data
														.istrue
												});
											}
										}
									});
							});

					},
					fail: function(res) {
						console.log(res);
					}
				});

			} catch (e) {

			}
		}
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow(options) {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})